<template>
  <div class="page-container">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-background">
        <div class="bg-pattern"></div>
        <div class="bg-gradient"></div>
      </div>
      
      <div class="page-title">
        <div class="title-icon">
          <div class="icon-container" style="width: 36px; height: 36px; background: linear-gradient(135deg, #ff9800 0%, #ffb74d 100%); border-radius: 8px; color: white; box-shadow: 0 2px 8px rgba(255, 152, 0, 0.2);">
            <el-icon size="20"><Tools /></el-icon>
            <div class="icon-glow"></div>
          </div>
        </div>
        <div class="title-content">
          <div class="title-main">
            <h1>数据工具</h1>
            <div class="title-badge">
              <el-icon><Star /></el-icon>
              <span>TOOLS</span>
            </div>
          </div>
          <p class="page-description">
            <el-icon><Monitor /></el-icon>
            统一的数据处理和监控工具集合
          </p>
          <div class="title-meta">
            <div class="meta-item">
              <el-icon><DataAnalysis /></el-icon>
              <span>数据分析</span>
            </div>
            <div class="meta-item">
              <el-icon><Connection /></el-icon>
              <span>实时监控</span>
            </div>
            <div class="meta-item">
              <el-icon><Setting /></el-icon>
              <span>配置管理</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 工具卡片网格 -->
    <div class="cards-grid">
      <el-card 
        v-for="tool in tools" 
        :key="tool.name"
        class="feature-card"
        shadow="hover"
        @click="navigateToTool(tool)"
        style="cursor: pointer;"
      >
        <div class="status-badge">
          <el-tag :type="tool.status === 'active' ? 'success' : 'info'" size="small">
            {{ tool.status === 'active' ? '可用' : '开发中' }}
          </el-tag>
        </div>
        <div class="card-content-layout">
          <div class="card-content-icon" :style="{ background: `linear-gradient(135deg, ${tool.color}15 0%, ${tool.color}08 100%)` }">
            <el-icon :size="32" :color="tool.color">
              <component :is="tool.icon" />
            </el-icon>
          </div>
          <div class="card-content-body">
            <h3 class="card-content-title">{{ tool.title }}</h3>
            <p class="card-content-description">{{ tool.description }}</p>
            <div class="features-list">
              <span 
                v-for="feature in tool.features" 
                :key="feature"
                class="feature-tag"
              >
                <el-icon><Check /></el-icon>
                {{ feature }}
              </span>
            </div>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, markRaw } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { 
  Link, Monitor, Connection, DataLine, Message, Clock, Document,
  Tools, Setting, Star, DataAnalysis, Check
} from '@element-plus/icons-vue'
import { componentLogger } from '@/utils/logger'

const router = useRouter()
// 工具列表
const tools = ref([
  {
    name: 'api-listener',
    title: 'API监听',
    description: '调用第三方接口，监听Kafka数据，智能匹配返回结果',
    icon: markRaw(Link),
    color: '#409EFF',
    status: 'active',
    features: ['API触发', 'Kafka监听', '智能匹配', '实时结果'],
    path: '/tools/api-listener'
  },
  {
    name: 'kafka-monitor',
    title: 'Kafka监听',
    description: '实时监听Kafka数据流，支持智能匹配和过滤',
    icon: markRaw(Monitor),
    color: '#67C23A',
    status: 'active',
    features: ['实时监听', '智能过滤', '环境切换', '数据导出'],
    path: '/tools/kafka-monitor'
  },
  {
    name: 'kafka-forward',
    title: 'Kafka转发',
    description: '从源Topic消费消息并转发到目标Topic',
    icon: markRaw(Connection),
    color: '#E6A23C',
    status: 'active',
    features: ['消息转发', '批量处理', '过滤规则', '实时统计'],
    path: '/tools/kafka-forward'
  },
  {
    name: 'timestamp-converter',
    title: '时间戳转换',
    description: 'Unix时间戳与日期时间格式相互转换工具',
    icon: markRaw(Clock),
    color: '#409EFF',
    status: 'active',
    features: ['时间戳转日期', '日期转时间戳', '快捷转换', '多时区支持'],
    path: '/tools/timestamp-converter'
  },
  {
    name: 'starrocks',
    title: 'StarRocks管理',
    description: 'StarRocks事务管理与任务监控，支持批量回滚与任务停止',
    icon: markRaw(DataLine),
    color: '#F56C6C',
    status: 'active',
    features: ['事务查询', '批量回滚', 'SQL执行', '任务查询', '任务停止', '历史记录'],
    path: '/tools/starrocks'
  },
  {
    name: 'callback',
    title: '回调服务',
    description: '通用回调数据接收、存储、查询功能',
    icon: markRaw(Message),
    color: '#9c27b0',
    status: 'active',
    features: ['数据接收', '统计分析', '历史查询', '状态管理'],
    path: '/tools/callback'
  },
  {
    name: 'json-formatter',
    title: 'JSON格式化',
    description: 'JSON数据格式化、压缩、验证工具',
    icon: markRaw(Document),
    color: '#409EFF',
    status: 'active',
    features: ['自动格式化', '特殊字符转义', '保存文件', '压缩', '语法高亮', '左右对比'],
    path: '/tools/json-formatter'
  }
])

// 导航到工具页面
const navigateToTool = (tool) => {
  if (tool.status !== 'active') {
    ElMessage.warning('该工具正在开发中，敬请期待')
    return
  }
  
  componentLogger.info('导航到工具页面', { tool: tool.name, path: tool.path })
  router.push(tool.path)
}
</script>

<style scoped>
/* 使用全局设计系统样式 */
/* 页面特定样式可以在这里添加 */
.page-container {
  background: transparent !important;
  padding: 0;
}

/* 页面标题样式 - 与 Jobs 页面保持一致 */
.page-header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 20px 24px;
  border-radius: 12px;
  overflow: hidden;
  color: #303133;
  min-height: 120px;
  border: 1px solid #e4e7ed;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.header-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0.05;
  pointer-events: none;
}

.title-icon {
  position: relative;
}

.page-header .title-icon .icon-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px !important;
  height: 36px !important;
  border-radius: 8px !important;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(255, 152, 0, 0.2) !important;
}

.page-header .title-icon .icon-container:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(255, 152, 0, 0.3) !important;
}

.page-header .title-icon .icon-glow {
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  background: linear-gradient(45deg, rgba(255, 152, 0, 0.2), rgba(255, 183, 77, 0.3));
  border-radius: 12px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.page-header .title-icon .icon-container:hover .icon-glow {
  opacity: 1;
}

.title-content {
  flex: 1;
}

.title-main {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.title-main h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: #303133;
  letter-spacing: -0.3px;
}

.title-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: linear-gradient(135deg, #ff9800 0%, #ffb74d 100%);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(255, 152, 0, 0.25);
}

.page-description {
  margin: 0 0 12px 0;
  color: #606266;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-description .el-icon {
  font-size: 16px;
  color: #909399;
}

.title-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #909399;
  font-size: 12px;
  font-weight: 500;
}
</style>
